﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using MusicStore.Data.Repository;
using MusicStore.Entities;
using MusicStore.Entities.Faults;

namespace MusicStore.WebService
{
	// NOTE: If you change the interface name "IMusicStoreService" here, you must also update the reference to "IMusicStoreService" in Web.config.
	[ServiceContract]
	public interface IMusicStoreService
	{
		[OperationContract]
		string GetData(int value);

		[OperationContract]
		CompositeType GetDataUsingDataContract(CompositeType composite);

		[OperationContract, FaultContract(typeof(FaultDetail))]
		void ThrowException();

		// Add your service operations here

		[OperationContract, FaultContract(typeof(FaultDetail))]
		List<AlbumSummary> GetAlbums();

		[OperationContract, FaultContract(typeof(FaultDetail))]
		List<Genre> GetGenres();

		[OperationContract, FaultContract(typeof(FaultDetail))]
		List<Author> GetAuthors();

		[OperationContract(Name = "GetAuthorsFilter"), FaultContract(typeof(FaultDetail))]
		List<Author> GetAuthors(string startWidth);

		[OperationContract(Name = "GetLabelsFilter"), FaultContract(typeof(FaultDetail))]
		List<Label> GetLabels(string startWidth);

		/// <summary>
		/// perform a search on the albums stored
		/// </summary>
		/// <param name="text">text to search</param>
		/// <returns></returns>
		[OperationContract, FaultContract(typeof(FaultDetail))]
		List<AlbumSummary> SearchAlbums(string text);

		[OperationContract, FaultContract(typeof(FaultDetail))]
		Album GetAlbum(int id);

		/// <summary>
		/// returns the Uri of an album (can be used to update the preview after uploading a new file)
		/// </summary>
		/// <param name="id">id of the album</param>
		/// <returns>The new uri</returns>
		[OperationContract, FaultContract(typeof(FaultDetail))]
		string GetAlbumPreviewUri(int id);

		/// <summary>
		/// saves an album and returns the id assigned to the new object
		/// </summary>
		/// <param name="album">the album object to create or update</param>
		/// <returns>the id assigned to the album we inserted</returns>
		[OperationContract, FaultContract(typeof(FaultDetail))]
		int Save(Album album);

		/// <summary>
		/// deletes an album
		/// </summary>
		/// <param name="id">id of the album to delete</param>
		[OperationContract, FaultContract(typeof(FaultDetail))]
		void Delete(int id);
	}

	// Use a data contract as illustrated in the sample below to add composite types to service operations.
	[DataContract]
	public class CompositeType
	{
		bool boolValue = true;
		string stringValue = "Hello ";

		[DataMember]
		public bool BoolValue
		{
			get { return boolValue; }
			set { boolValue = value; }
		}

		[DataMember]
		public string StringValue
		{
			get { return stringValue; }
			set { stringValue = value; }
		}
	}
}
